#include <e32svr.h>

#include "ObserverSession.h"
#include "clientservercommon.h"
#include "Logger.h"

CMySession::CMySession(CMyServer& aServer)
:   CSession2(), iServer(aServer)
{
}

CMySession::~CMySession()
{
LOG_WRITE("~CMySession");
	iServer.DecrementSessions();
}

void CMySession::ServiceL(const RMessage2& aMessage)
{
LOG_WRITE("ServiceL");
	TInt res = DispatchMessageL(aMessage);
	aMessage.Complete(res);
}
	
TInt CMySession::DispatchMessageL(const RMessage2& aMessage)
{
	TInt res = KErrNone;
	switch (aMessage.Function())
	{
		case EUpdateSettings:
			iServer.ReloadSettings();
			break ;
		default:
			PanicClient(aMessage, EBadRequest);
			break;
	}
	return res;
}

void CMySession::PanicClient(const RMessage2& aMessage, TInt aPanic) const
{
LOG_WRITE("panic client");
	aMessage.Panic(KCSSyncServer, aPanic);
}

CMySession* CMySession::NewL(CMyServer& aServer)
{
	CMySession* self = CMySession::NewLC(aServer) ;
	CleanupStack::Pop(self) ;
	return self ;
}

CMySession* CMySession::NewLC(CMyServer& aServer)
{
	CMySession* self = new (ELeave) CMySession(aServer);
	CleanupStack::PushL(self) ;
	self->ConstructL() ;
	return self ;
}

void CMySession::ConstructL()
{
	iServer.IncrementSessions();
}
